M98 P"0:/sys/led/resetstatus.g"

; Relax all XYU motors before manual movement test (in case of restart without homing)
M84 XYU
G4 S1

M564 H0

M291 R"Move Tools by Hand Test" P"Manually move both tool heads along X, Y, and U axes.<br><br>Check that movement is smooth and without binding.<br><br>Pay attention to any unusual resistance or sounds." S4 K{"Movement was Smooth","Cancel"}
if input == 1
    abort "Test cancelled by user"

M291 R"Move XYU Axes Manually" P"Manually move both tool heads by hand.<br>Test all axes: X (left tool), U (right tool), and Y (Cross Bar)." S3 X1 Y1 U1

M302 P0

M564 H0
M291 R"Z - Motor Connection Test" P"Each motor will move in sequence: Left, Right, Rear" S4 K{"Test","Raise Build Plate","Skip","Cancel"}
if input == 1
    ; Raise Up option - move Z-axis up by 25mm
    M564 H0 ; Ensure movement without homing is allowed
    G91 ; Set to relative positioning
    G1 Z-25 F18000 ; Move Z-axis up by 25mm (negative Z = up)
    G90 ; Set to absolute positioning
    M400 ; Wait for movement to complete
    M291 R"Z - Motor Connection Test" P"Z-axis raised by 25mm.<br><br>Each motor will move in sequence: Left, Right, Rear" S4 K{"Test","Skip","Cancel"}
    if input == 1
        M99
    elif input == 2
        abort "Test cancelled by user"
elif input == 2
    M99
elif input == 3
    abort "Test cancelled by user"

M913 Z75 ; Reduce Z-axis current to 75% for safe motor testing

; Move Left lead screw
M584 Z1.2     ; define driver mapping

G91               ; set to relative positioning
G1 F18000 Z10    ; move 10mm down
G1 F18000 Z-20     ; move 20mm up
G1 F18000 Z10    ; move 10mm down back to original position
G90               ; set to absolute positioning

M400

; Move Right lead screw
M584 Z1.0     ; define driver mapping

G91               ; set to relative positioning
G1 F18000 Z10    ; move 10mm down
G1 F18000 Z-20     ; move 20mm up
G1 F18000 Z10    ; move 10mm down back to original position
G90               ; set to absolute positioning

M400

; Move Rear lead screw
M584 Z1.1     ; define driver mapping

G91               ; set to relative positioning
G1 F18000 Z10    ; move 10mm down
G1 F18000 Z-20     ; move 20mm up
G1 F18000 Z10    ; move 10mm down back to original position
G90               ; set to absolute positioning

M400
M584 Z1.0:1.1:1.2 ; restore original driver mapping
M906 X1800 U1800 Y1800:1800 Z850 E600:600 I35 T10
M913 Z100 ; Reset Z-axis current to 100%

M564 H1
